window.addEventListener('load', function () {
    let albumimg = document.querySelector('.index-con_albumimgbox');
    let arrow_l = this.document.querySelector('.index-con_albumarrowl');
    let arrow_r = this.document.querySelector('.index-con_albumarrowr');
    let albumimgWidth = albumimg.offsetWidth;

    // 鼠标经过隐藏左右按钮
    albumimg.addEventListener('mouseenter', function () {
        arrow_l.style.display = 'block';
        arrow_r.style.display = 'block';
        clearInterval(timer);
        timer = null;//清除定时器变量
    });
    albumimg.addEventListener('mouseleave', function () {
        arrow_l.style.display = 'none';
        arrow_r.style.display = 'none';
        timer = setInterval(function () {
            //手动调用点击事件
            arrow_l.click();
        }, 2000);
    });

    let ul = albumimg.querySelector('.index-con_albumlunbo');
    //克隆第一张放到最后面
    let first = ul.children[0].cloneNode(true);
    ul.appendChild(first);
    let num = 0;
    arrow_r.addEventListener('click', function () {
        if (num == ul.children.length - 1) {
            ul.style.left = 0;
            num = 0;
        }
        num++;
        animate(ul, -num * albumimgWidth, function () {
        });
    })
    arrow_l.addEventListener('click', function () {
        if (num == 0) {
            num = ul.children.length - 1;
            ul.style.left = -num * albumimgWidth + 'px';
        }
        num--;
        animate(ul, -num * albumimgWidth, function () {
        });
    });
    // 自动播放轮播图
    let timer = setInterval(function () {
        //手动调用点击事件
        arrow_l.click();
    }, 2000);
});